package com.witte.serviceImp;

import com.witte.dao.CustomerMapper;
import com.witte.entity.Customer;
import com.witte.entity.Echarts;
import com.witte.entity.Statitic;
import com.witte.service.CusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class CusServiceImp implements CusService {

    @Autowired(required=false)
    CustomerMapper customerMapper;

    @Override
    public List<Customer> selectAllCus() {
        List<Customer> customer = customerMapper.selectAllCus();
        return customer;
    }

    @Override
	public Map<String,List<Object>> selectAllCusByLevel() {
		// TODO Auto-generated method stub
    	List<Object> xList = new ArrayList<>();
    	for(Statitic i:customerMapper.selectAllCusByLevel()) {
			xList.add(new Echarts(i.getLevelName(),i.getCount()));
		}
    	Map<String,List<Object>> ret = new HashMap<>();
    	ret.put("x", xList);
        return ret;
	}

	@Override
	public Map<String,List<Object>> selectAllCusByCredit() {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		List<Object> xList = new ArrayList<>();
		List<Object> yList = new ArrayList<>();
		for(Statitic i:customerMapper.selectAllCusByCredit()) {
			xList.add(i.getCreditName());
			yList.add(i.getCount());
		}
		Map<String,List<Object>> ret = new HashMap<>();
		ret.put("x", xList);
		ret.put("y", yList);
        return ret;
	}

	@Override
	public Map<String,List<Object>> selectAllCusByStatify() {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		List<Object> xList = new ArrayList<>();
		List<Object> yList = new ArrayList<>();
		for(Statitic i:customerMapper.selectAllCusByStatisfy()) {
			xList.add(i.getSatisfyName());
			yList.add(i.getCount());
		}
		Map<String,List<Object>> ret = new HashMap<>();
		ret.put("x", xList);
		ret.put("y", yList);
        return ret;
	}

	@Override
	public int updateByCusNo(Customer customer) {
		int updateCus = customerMapper.updateByPrimaryKey(customer);
		return updateCus;
	}

	@Override
	public List<Customer> getNameList(String name, Integer beginPage, Integer pageSize) {
		int begain= (beginPage-1)*pageSize;
		return customerMapper.selectByName(name,begain,pageSize);
	}

	@Override
	public int getNameCount(String name) {
		return customerMapper.getNameCount(name);
	}

	@Override
	public int insert(Customer customer) {
		int insertCus = customerMapper.insert(customer);
		return insertCus;
	}

	@Override
	public List<com.witte.entity.Customer> getStateList(Integer beginPage, Integer pageSize) {
		int begain = (beginPage-1)*pageSize;
		return customerMapper.selectByState(begain,pageSize);
	}

	@Override
	public int getRecodeCount() {
		return customerMapper.getRecodeCount();
	}

	@Override
	public int deleteByPrimaryKey(Integer customerno) {
			int delectCus = customerMapper.deleteByPrimaryKey(customerno);
		return delectCus;
	}

	@Override
	public Customer selectByNo(Integer customerno) {
		return customerMapper.selectByNo(customerno);
	}

	@Override
	public String selectNameByNo(Integer no) {
		// TODO Auto-generated method stub
		return customerMapper.selectNameByNo(no);
	}
	
	/*@Override
	public Customer selectByPrimaryKey(Integer customerno) {
		return customerMapper.selectByPrimaryKey(customerno);
	}*/


}
